#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=100005;
ll T,n,m,L,V,p[N],ans,cnt;
struct node{
    ll d,v,a;
    ll ls,rs;
}c[N];
bool cmp(node pp,node qq){
    return pp.rs<=qq.rs;
}

int erfen(int k){
    int l=1,r=m;
    if(k<=p[1]){
        return 1;
    }
    if(k>=p[m]){
        return m+1;
    }
    while(l<r){
        int mid=(l+r)/2;
        if(p[mid]<=k&&k<=p[mid+1]){
            if(k!=p[mid]){
                mid++;
            }
            return mid;
        }
        else if(k>p[mid+1]){
            l=mid+1;
        }
        else if(k<p[mid]){
            r=mid;
        }
    }
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    while(T--){
        memset(p,0,sizeof(p));
        ans=0;
        cnt=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>c[i].d>>c[i].v>>c[i].a;
            if(c[i].a==0){
                cnt++;
            }
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        sort(p+1,p+1+m);
        /*for(int i=1;i<=m;i++){
            cout<<p[i]<<" ";
        }cout<<endl;*/
        for(int i=1;i<=n;i++){
            if(c[i].d>p[m]){
                continue;
            }
            if(c[i].a==0&&c[i].d<=p[m]&&c[i].v>V){
                ans++;
                //cout<<i<<c[i].ls<<" "<<c[i].rs<<endl;
                c[i].rs=m;
                c[i].ls=erfen(c[i].d);
                continue;
            }
            if(c[i].a>0){
                int k=0;
                if(c[i].v>V){
                    k=0;
                }
                else{
                    k=(V*V-c[i].v*c[i].v)/2/c[i].a;
                }
                int ss=erfen(k+c[i].d);
                if(ss<=m){
                    ans++;
                    //cout<<i<<c[i].ls<<" "<<c[i].rs<<endl;
                    c[i].ls=ss;
                    c[i].rs=m;
                }
                continue;
            }
            if(c[i].a<0&&c[i].v>V){
                int k=(V*V-c[i].v*c[i].v)/2/c[i].a;
                int s1=erfen(c[i].d);
                int s2=erfen(c[i].d+k)-1;
                if(s1<=s2){
                    c[i].ls=s1;
                    c[i].rs=s2;
                    ans++;
                    //cout<<i<<c[i].ls<<" "<<c[i].rs<<endl;
                }
            }
        }
        sort(c+1,c+1+n,cmp);
        /*for(int i=1;i<=n;i++){
            cout<<c[i].ls<<" "<<c[i].rs<<" ";cout<<endl;
        }*/
        if(cnt==n){
            cout<<ans<<" "<<m-1<<endl;
            break;
        }
        for(int i=1;i<=n;i++){
            if(c[i].rs==0&&c[i].ls==0){
                continue;
            }
            m--;
            for(int j=i+1;j<=n;j++){
                if(c[i].rs>=c[j].ls){
                    c[j].rs=c[j].ls=0;
                }
            }
        }

        cout<<ans<<" "<<m<<endl;
    }




    return 0;
}
